var tblChild;
var url_ChildData = basePath + "teacher/getChildData";
var url_GetChildData = basePath + "teacher/getSearchChildData";
var name;
$(function () {
    tblChild = $('#tbl-child').DataTable(buildChildOptions());
    trCssEvent(tblChild);
    $("#btn-search-child").click(centerSearch);
    // getchildData();
});

function buildChildOptions() {
    var options = {
        "searching": false,
        "ordering": true,
        "processing": true,
        "scrollX": true,
        "language": {
            "url": plugPath + 'DataTables/chinese.json'
        },
        "serverSide": true,
        "ajax": {
            "url": url_ChildData,
            "type": 'POST',
            data: function (params) {
                params['name'] = $("#name").val();
                params['centerId'] = $("#centerId").val();
            }
        },

        "columns": [{
            "data": "name"
        }, {
            "data": "sex"
        }, {
            "data": "age"
        },  {
            "data": "grade"
        },  {}],
        columnDefs: [{
            "targets": [4],
            "data": "id",
            "render": function (data, type, row, meta, full) {
                return "<a href='goSchedulePage?childId="+data+"' target='_blank'>【查看课程】</a>";
            }
        },{"orderable": false, "targets": [0, 1, 3, 4]}],

        "dom": "<'row'<'col-xs-12't>><'row'<'col-xs-2 lstyle'l><'col-xs-3'i><'col-xs-6  fright'p>>"

    };
    return options;
}


// //查询搜索中心
function centerSearch() {
    $("#btn-search-child").attr("disabled", "disabled");
    tblChild.ajax.reload(function () {
        $("#btn-search-child").removeAttr("disabled");
    });
}

// 孩子名字模糊提示
function getchildData() {
    var centerId = $("#centerId").val();
    var childData = [];
    $.ajax({
        url: url_GetChildData,
        data: {centerId:centerId},
        type: "post",
        success: function (pm) {
            if (pm != null) {
                var childDatas = [];
                childData = pm;
                var dataLength = childData.length;
                for (var i = 0; i < dataLength; i++) {
                    var childname = childData[i].name;
                    var teacherName = childData[i].teacherName;
                    var tamp = childname + "中心:" + teacherName ;
                    var obj ;
                    obj = {label:tamp,value:childname};
                    childDatas.push(obj);
                }
                doSelectChild(childDatas);
            } else {
                alert("获取基本信息异常,请联系管理员");
            }
        }
    })
}

function doSelectChild(data) {
    $("#name").autocomplete({
        source: data,
        select: function (event, ui) {
            name = ui.item.childname;
        }
    });
}